var express = require('express');
var router = express.Router();
var multer = require('multer');
var path = require('path');


// 多文件上传/拖拽上传/剪切板上传
const storage = multer.diskStorage({
    destination: 'upload',
    filename(req, file, cb) {
        // 获取文件名后缀
        const ext = path.extname(file.originalname);
        // 随机生成文件名
        const uniqueSuffix = Date.now() + '_' + Math.round(Math.random() * 1e9);
        const fileName = `${uniqueSuffix} + ${ext}`;
        cb(null, fileName)
    }
})

// 多文件上传/拖拽上传
const upload = new multer({ storage })
router.post("/upload", upload.array('files'), (req, res) => {
    const files = req.files
    const name = req.body.name
    const email = req.body.email
    console.log(files, name, email);
    if (!files) {
        res.send('File not found')
        return;
    }
    res.send('文件上传成功')
})


module.exports = router;
